package ac.github.os.internal.session

import ac.github.os.api.common.SingleList
import ac.github.os.internal.core.holder.EventHolder
import ac.github.os.internal.core.holder.Holder
import ac.github.os.internal.core.objective.EntityObjective
import ac.github.os.internal.core.objective.LocationObjective
import ac.github.os.internal.core.objective.Objective
import ac.github.os.internal.core.script.BaseWrapper
import ac.github.os.internal.core.script.impl.*
import ac.github.os.internal.core.skill.SkillScheme
import ac.github.os.internal.core.trigger.Trigger
import org.bukkit.Location
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player

class Session(
    val trigger: Trigger,
    val holder: Holder
) : BaseWrapper {

    val list = mutableListOf(
        this,
        EvalScript.Wrapper(),
        RandomScript.Wrapper(),
        PlayerScript.Wrapper(),
        StoreScript.Wrapper(),
        PlaceholderScript.Wrapper()
    )

    init {
        if (holder is EventHolder<*>) {
            list.add(EventScript.Wrapper(holder))
        }
    }

}

class Cache {
    val objectives = SingleList<Objective>()

    fun filterIsPlayers(): List<Player> {
        return filterIsEntities().filterIsInstance<Player>()
    }

    fun filterIsEntities(): List<LivingEntity> {
        return objectives
            .filterIsInstance<EntityObjective>()
            .map { it.entity }
    }

    fun filterIsLocation(): List<Location> {
        return objectives
            .filterIsInstance<LocationObjective>()
            .map { it.location }
    }

}